package com.springmvc.springbootOne;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication
public class Application {
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
      
  	//根据错误状态码 转向页面
  	@Bean
  	public EmbeddedServletContainerCustomizer containerCustomizer() {
  	    return new EmbeddedServletContainerCustomizer() {
  	    	//此处如果不定义，就会去templates下着error.html文件，如果没有error.html文件就会报系统自带的错误提示
  	    	//所以此处可理解为自定义错误处理界面
  	        public void customize(ConfigurableEmbeddedServletContainer container) {
  	            ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401.html");
  	            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404.html");
  	            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500.html");
  	            container.addErrorPages(error401Page, error404Page, error500Page);
  	            //container.setSessionTimeout(10,TimeUnit.SECONDS);//设置超时时间
  	            //container.setPort(8081);
  	        }
  	    };
  	}
      
}
